<template>
  <div class="app-container">
    <el-amap :center="center" :zoom="zoom" class="amap-div">
      <el-amap-control-scale :visible="true"/>
      <el-amap-control-hawk-eye :visible="true"/>
      <el-amap-control-map-type :visible="true"/>
      <el-amap-control-geolocation :visible="true" @complete="getLocation"/>
      <el-amap-marker v-for="(marker, index) in markers" :key="index" :position="marker.position"
                      @click="(e) => { clickArrayMarker(marker, e) }">
        <div class="point point-flicker"></div>
      </el-amap-marker>
    </el-amap>
    <el-form v-show="showShipment" ref="shipForm" :inline="true" :model="shipData" label-width="100px" size="small">
      <el-form-item label="车牌">
        <el-input v-model="shipData.card" readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="司机">
        <el-input v-model="shipData.driver" readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="shipData.phone" readonly="readonly"></el-input>
      </el-form-item>
      <el-form-item label="最近刷新时间">
        <el-input v-model="shipData.lastTime" readonly="readonly"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {v4 as uuidv4} from 'uuid';


export default {
  name: 'VehicleTrace',
  data() {
    return {
      zoom: 12,
      center: [102.829208, 24.852349],
      mapPosData: {},
      shipData: {
        card: '',
        driver: '',
        phone: '',
        lastTime: null,
      },
      showShipment: false,
    }
  },
  computed: {
    markers() {
      return [
        {
          position: [102.829208, 24.852349],
          id: uuidv4(),
          card: '云A347538'
        },
        {
          position: [102.849208, 24.822349],
          id: uuidv4(),
          card: '云A8955E'
        },
      ]
    },
  },
  methods: {
    getLocation(e) {
      console.log('getLocation: ', e)
    },
    clickArrayMarker(marker, e) {
      this.showShipment = true
      this.shipData.card = marker.card
      this.shipData.driver = '张三'
      this.shipData.phone = '13888888888'
      this.shipData.lastTime = new Date().toLocaleString()
    },
  }

}
</script>

<style lang="scss">
.amap-div {
  margin-bottom: 10px;
  min-height: 600px;
  height: 600px;
}

.point {
  width: 12.5px;
  height: 12.5px;
  background-color: #8651e0;
  position: relative;
  border-radius: 50%;
}

/* 设置动画前颜色 */
.point-flicker:after {
  background-color: #8651e0;
}

/* 设置动画后颜色 */
.point-flicker:before {
  background-color: rgba(0, 168, 253, 0.2);
}

/* 设置动画 */
.point-flicker:before,
.point-flicker:after {
  content: '';
  width: 20px;
  height: 20px;
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -10px;
  margin-top: -10px;
  border-radius: 50%;
  animation: warn 1.5s ease-out 0s infinite;
}

@keyframes warn {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }

  30% {
    opacity: 1;
  }

  100% {
    transform: scale(1.4);
    opacity: 0;
  }
}
</style>
